package com.chenwut.stringDemo;

import java.util.Scanner;

public class StringDemo5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int money;
        while (true) {
            System.out.println("请输入一个金额");
            money = sc.nextInt();
            if (money >= 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("金额无效");
            }
        }
        //定义一个变量表示钱的大写
        String moneyStr = "";
        while (true) {
            int temp = money % 10;
            money = money / 10;
            String capitalNumber = getCapitalNumber(temp);
            moneyStr = capitalNumber + moneyStr;

            if (money == 0) {
                break;
            }
        }


        //在前面补0，补齐7位
        int count = 7 - moneyStr.length();
        for (int i = 0; i < count; i++) {
            moneyStr = "零" + moneyStr;
        }

        //插入单位
        String result ="";
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};
        for (int i = 0; i < moneyStr.length(); i++) {
            char c = moneyStr.charAt(i);
            //把大写数字和单位拼接到result中
            result = result + c + arr[i];
        }


        System.out.println(result);
    }

    //定义一个方法把数字变成大写的中文
    //1 ——> 壹
    public static String getCapitalNumber(int number) {
        String[] arr = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
        return arr[number];
    }

}
